#include <jni.h>
#include <string>

jmethodID  g_onWriteMethod;
JavaVM* g_vm;
jobject g_obj;


extern "C" JNIEXPORT jstring JNICALL
Java_com_example_lsxclasswork3_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */obj) {
    std::string hello = "Hello from C++";

    g_vm=NULL;
    env->GetJavaVM(&g_vm);
    g_obj=env->NewGlobalRef(obj);
    jclass cls = env->GetObjectClass(obj);
    g_onWriteMethod = env->GetMethodID(cls,"onWriteFromCpp","(I)V");

    return env->NewStringUTF(hello.c_str());
}

extern "C" JNIEXPORT jint JNICALL
Java_com_example_lsxclasswork3_MainActivity_add(
        JNIEnv* env,jclass ,jint a,jint b) {
    env->CallVoidMethod(g_obj,g_onWriteMethod,15);
    return a+b;
}

